using System.Collections.Generic;
using Arcane.Source.Client.Sections;
using Godot;

namespace Arcane.Source.Client
{
    public class RichTextBuilder
    {
        private readonly List<IRichTextSection> _sections;

        public RichTextBuilder()
        {
            _sections = [];
        }

        public RichTextBuilder NewLine()
        {
            _sections.Add(new NewLine());
            return this;
        }

        public RichTextBuilder Line(string text, int fontSize = 14)
        {
            if (!string.IsNullOrEmpty(text))
                _sections.Add(new Common(new(text, fontSize)));

            return NewLine();
        }


        public RichTextBuilder BoldLine(string text, int fontSize = 14)
        {
            if (!string.IsNullOrEmpty(text))
                _sections.Add(new Bold(new(text, fontSize)));

            return NewLine();
        }

        public RichTextBuilder ColoredLine(int color, string text, int fontSize = 14)
        {
            if (!string.IsNullOrEmpty(text))
                _sections.Add(new Colored(color, new(text, fontSize)));

            return NewLine();
        }
    }

    public readonly struct Text(string content, int fontSize)
    {
        public readonly int FontSize => fontSize;
        public readonly string Content => content;
    }

    namespace Sections
    {
        public interface IRichTextSection { }

        public readonly struct NewLine : IRichTextSection;

        public readonly struct Common(Text text) : IRichTextSection
        {
            public readonly Text Text => text;
        }

        public readonly struct Colored(int color, Text text) : IRichTextSection
        {
            public readonly int Color => color;
            public readonly Text Text => text;
        }

        public readonly struct Bold(Text text) : IRichTextSection
        {
            public readonly Text Text => text;
        }

        public readonly struct Image(Texture2D texture, int? width = null, int? height = null) : IRichTextSection
        {
            public readonly Texture2D Texture => texture;
            public readonly int? Width => width;
            public readonly int? Height => height;
        }
    }
}